package com.mi.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

/**
 * 设置所有request和response的编码过滤器
 */
// /*表示在所有文件目录下都进行过滤
@WebFilter("/*")
public  class CharsetEncodingFilter implements Filter {

	/**
	 * 过滤器业务处理
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// 过滤器业务处理
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		// 必须有，继续在过滤器链上向下传递
		chain.doFilter(request, response);
		// System.out.println("执行了设置编码过滤器");
	}

	/**
	 * 获取配置信息
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}



}
